#include "../Headers/logAPICall.hpp"
#include "../Headers/tLogger.hpp"
#include "../Headers/tFormatter.hpp"

using namespace std;

void PrintAPI::Entrance(string commandName) {
	TLogger::writeLineX("[API call] " + commandName, false, true);
}

void PrintAPI::EntranceInts(string commandName, int* para0, int* para1, int* para2, int* para3, int* para4) {
	string paraList;
	if (para0 != nullptr) {
		paraList += "," + TFormater::int2str(*para0);
		if (para1 != nullptr) {
			paraList += "," + TFormater::int2str(*para1);
			if (para2 != nullptr) {
				paraList += "," + TFormater::int2str(*para2);
				if (para3 != nullptr) {
					paraList += "," + TFormater::int2str(*para3);
					if (para4 != nullptr) {
						paraList += "," + TFormater::int2str(*para4);
					}
				}
			}
		}
	}
	PrintAPILineCore("[API call] " + commandName + "(" + paraList + ")");
}

void PrintAPI::EntranceFloats(string commandName, int* slideIdx, float* paras, int paraNum) {
	string paraList;
	if (slideIdx != nullptr) {
		paraList += "#" + TFormater::int2str(*slideIdx);
	}
	paraList += ",[" + TFormater::floats2str(paras, paraNum) + "]";

	PrintAPILineCore("[API call] " + commandName + "(" + paraList + ")");
}

void PrintAPI::EntranceFloats(string commandName, int* slideIdx, float* para0, float* para1, float* para2, float* para3, float* para4) {
	string paraList;
	if (slideIdx != nullptr) {
		paraList += "#" + TFormater::int2str(*slideIdx);
	}
	if (para0 != nullptr) {
		paraList += "," + TFormater::float2str(*para0);
		if (para1 != nullptr) {
			paraList += "," + TFormater::float2str(*para1);
			if (para2 != nullptr) {
				paraList += "," + TFormater::float2str(*para2);
				if (para3 != nullptr) {
					paraList += "," + TFormater::float2str(*para3);
					if (para4 != nullptr) {
						paraList += "," + TFormater::float2str(*para4);
					}
				}
			}
		}
	}
	PrintAPILineCore("[API call] " + commandName + "(" + paraList + ")");
}

void PrintAPI::EntranceInt3Floats(string commandName, int* slideIdx, int* para0, int* para1, float* paras, int paraNum) {
	string paraList;
	if (slideIdx != nullptr) {
		paraList += "#" + TFormater::int2str(*slideIdx);
	}
	paraList += "," + TFormater::int2str(*para0);
	paraList += "," + TFormater::int2str(*para1);
	paraList += ",[" + TFormater::floats2str(paras, paraNum) + "]";

	PrintAPILineCore("[API call] " + commandName + "(" + paraList + ")");
}

void PrintAPI::EntranceStr(string commandName, wstring para0) {
	TLogger::write("[API call] " + commandName, false, true);
	TLogger::writeLineX(L"(" + para0 + L")");
}

void PrintAPI::EntranceStr(string commandName, string para0) {
	TLogger::write("[API call] " + commandName, false, true);
	TLogger::writeLineX("(" + para0 + ")");
}

void PrintAPI::EntranceStr(string commandName, std::wstring slave_name, wstring para0) {
	TLogger::write("[API call] " + commandName, false, true);
	if (slave_name.length() > 0) {
		TLogger::write(L"(" + slave_name + L")-");
	}
	TLogger::writeLineX(L"(" + para0 + L")");
}

void PrintAPI::EntranceStrs(std::string commandName, std::wstring para0, std::wstring para1) {
	TLogger::write("[API call] " + commandName, false, true);
	TLogger::writeLineX(L"(" + para0 + L"," + para1 + L")");
}

void PrintAPI::EntranceStrs(std::string commandName, std::wstring para0, std::wstring para1, std::wstring para2) {
	TLogger::write("[API call] " + commandName, false, true);
	TLogger::writeLineX(L"(" + para0 + L"," + para1 + L"," + para2 + L")");
}

void PrintAPI::EntranceStrs(std::string commandName, std::wstring para0, std::wstring para1, std::wstring para2, std::wstring para3) {
	TLogger::write("[API call] " + commandName, false, true);
	TLogger::writeLineX(L"(" + para0 + L"," + para1 + L"," + para2 + L"," + para3 + L")");
}

void PrintAPI::EntranceFlag(string commandName, bool* boolVal, int* intVal, float* floatVal) {
	TLogger::write("[API call] " + commandName, false, true);
	TLogger::write("(");
	if (boolVal != nullptr) {
		TLogger::write(", Bul: " + TFormater::bool2str(*boolVal));
	}
	if (intVal != nullptr) {
		TLogger::write(", Int: " + TFormater::int2str(*intVal));
	}
	if (floatVal != nullptr) {
		TLogger::write(", Flt: " + TFormater::float2str(*floatVal));
	}
	TLogger::writeLineX(")");
}

void PrintAPI::EntranceFlag(std::string commandName, std::wstring paraName, bool* boolVal, int* intVal, float* floatVal) {

}

void PrintAPI::Return(string commandName, int flag) {
	PrintAPILineCore("[API return] " + commandName + "->" + TFormater::int2str(flag));
}

std::wstring PrintAPI::Return(std::wstring Comment) {
	if (Comment.length() > 0 && !TWFormater::beginWith(Comment, L"ok")) {
		int stop = 1;
	}
	PrintAPILineCore(L"[API return] " + Comment);
	if (!TWFormater::beginWith(Comment, L"ok")) {
		int stop = 1;
	}
	return Comment;
}

void PrintAPI::Line(std::string content) {
	TLogger::writeLineX(content);
}

void PrintAPI::PrintAPILineCore(string line) {
	TLogger::writeLineX(line, false, true);
}

void PrintAPI::PrintAPILineCore(wstring line) {
	TLogger::writeLineX(line, false, true);
}